﻿using System;
using System.Windows.Forms;

namespace demo_cs
{
    public partial class AddCameraDialog : Form
    {
        public float EyeX { get; private set; }
        public float EyeY { get; private set; }
        public float EyeZ { get; private set; }
        public float AtX { get; private set; }
        public float AtY { get; private set; }
        public float AtZ { get; private set; }
        public float UpX { get; private set; }
        public float UpY { get; private set; }
        public float UpZ { get; private set; }
        public string CameraName { get; private set; }

        public AddCameraDialog(string name)
        {
            InitializeComponent();

            textBoxName.Text = name;

            DialogResult = DialogResult.Cancel;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxName.Text))
            {
                ErrorProvider err = new ErrorProvider();
                err.SetError(textBoxName, "Name is empty");
                return;
            }

            foreach (Control control in Controls)
            {
                TextBox textBox = control as TextBox;
                if (textBox != null & textBox != textBoxName)
                {
                    float value;
                    if (!(float.TryParse(textBox.Text, out value)))
                    {
                        ErrorProvider err = new ErrorProvider();
                        err.SetError(textBox, "Invalid value");
                        return;
                    }
                }
            }

            EyeX = float.Parse(textBoxEyeX.Text);
            EyeY = float.Parse(textBoxEyeY.Text);
            EyeZ = float.Parse(textBoxEyeZ.Text);
            AtX = float.Parse(textBoxAtX.Text);
            AtY = float.Parse(textBoxAtY.Text);
            AtZ = float.Parse(textBoxAtZ.Text);
            UpX = float.Parse(textBoxUpX.Text);
            UpY = float.Parse(textBoxUpY.Text);
            UpZ = float.Parse(textBoxUpZ.Text);
            CameraName = textBoxName.Text;

            DialogResult = DialogResult.OK;

            Close();
        }
    }
}
